﻿using UnityEngine;
using System.Collections;

public class RotateScrollScript : MonoBehaviour {

	private float maxDistance;
	private float minDistance;
	private float zoom;
	public Vector3 target;

	public GameObject target2;


	void Start () {
	
		target = Vector3.zero;
		
		zoom = 1.0f;
		
		maxDistance = 50.0f;
		minDistance = 1.0f;

	}
	

	void Update () {
		transform.LookAt(target2.GetComponent<ExpandScript>().puzzleCenter);
		Vector3 input = new Vector3 (Input.GetAxis ("Horizontal"), Input.GetAxis ("Vertical"), 0);
		if (input != Vector3.zero) {
			transform.Translate(input*1.5f);
		}

		{
		camera.transform.LookAt(target);
		Ray ray = new Ray(transform.position, transform.forward);
		if(Input.GetAxis("Mouse ScrollWheel") != 0){
			if(Input.GetAxis("Mouse ScrollWheel") > 0){
				
				Debug.Log("close");
				
				if(Vector3.Distance(transform.position, target) > minDistance)
					
					camera.transform.position = ray.GetPoint(zoom);
				
			}
			
			if(Input.GetAxis("Mouse ScrollWheel") < 0){
				Debug.Log("far");
				if(Vector3.Distance(transform.position, target) < maxDistance)
					camera.transform.position = ray.GetPoint(-zoom);
				
			}
			
		 }
		
		}
	}
}
